package com.thinkingstar.iads.datacenter.entity.dao;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.QueryResult;
import org.nutz.dao.pager.Pager;
import org.nutz.dao.sql.Criteria;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;

import com.thinkingstar.iads.common.serviceImpl.EntityRepositoryServiceImpl;
import com.thinkingstar.iads.common.utils.CommonDateUtil;
import com.thinkingstar.iads.datacenter.entity.DcEquipmentType;
import com.thinkingstar.iads.datacenter.entity.DcProjectDesignContent;

/**
 * @ClassName: DaoDcProjectDesignContent 
 * @Description:数据中心_项目_项目设备类型维护
 * @author 1157372219@qq.com 
 * @date 2018年3月19日   
 */
@IocBean(args = {"refer:dao"})
public class DaoDcEquipmentType extends EntityRepositoryServiceImpl<DcEquipmentType>{

	public DaoDcEquipmentType(Dao dao) {
		super(dao);
	}

	/**
	 * 分页查询项目设计类型
	 */
	public QueryResult findEquipmentType(NutMap nutMap){
		Pager pager = null;
		List <DcEquipmentType> page_list = null;
		Criteria criteria = Cnd.NEW();
		criteria.where().and("del_flag", "=", false);
		if(StringUtils.isNotBlank(nutMap.getString("code"))){
			criteria.where().and("equipment_type_code", "=", nutMap.get("code"));
		}
		if(StringUtils.isNotBlank(nutMap.getString("name"))){
			criteria.where().and("equipment_type_name", "like", "%"+nutMap.get("name")+"%");
		}
		criteria.getOrderBy().desc("create_time");
		if(nutMap.get("page_num") != null && nutMap.get("page_size") != null){
			pager = new Pager(nutMap.getInt("page_num"), nutMap.getInt("page_size"));
			pager.setRecordCount(dao().count(DcEquipmentType.class, criteria));
			page_list = query(criteria,pager);
		}else{
			page_list = query(criteria);
		}
		return new QueryResult(page_list,pager);
	}
	
	/**
	 * 更新项目设计类型
	 * @param dcEquipmentType
	 * @return
	 */
	public int updateEquipmentType(DcEquipmentType dcEquipmentType){
		if(dcEquipmentType == null){
			return 0;
		}
		int i = 0;
		if(StringUtils.isNotBlank(dcEquipmentType.getId())){
			DcEquipmentType update_obj = fetch(dcEquipmentType.getId());
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setEquipment_type_code(dcEquipmentType.getEquipment_type_code());
			update_obj.setEquipment_type_name(dcEquipmentType.getEquipment_type_name());
			i = update(update_obj);
		}else{
			dcEquipmentType.setCreate_time(CommonDateUtil.getDateTime());
			Object object = insert(dcEquipmentType);
			if(object != null){
				i = 1;
			}
		}
		return i;
	}
	
	
	

}
